#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import requests
from enum import Enum

class FsHook(Enum):
    """飞书自定义机器人列表"""

    # data_platform_log = "f0bdfae1-2afe-41aa-b555-6616c3ac6892"
    # """ 数据平台日志记录机器人 """
    #
    # kstock_front_log = "179fece1-51d8-4dad-94da-b7cd3e3aab65"
    # """ 前端日志上报的机器人 """

    uiAutomationReport = "4f849421-0a24-4fa8-94a8-f05441d2825e"
    """ ui自动化报告机器人 """


def send_feishu_rich_message(title, content, hook: FsHook = FsHook.uiAutomationReport):
    """发送日志到飞书机器人

    Args:
        title (str): 标题
        content (list): 内容
        hook (FsHook, optional): 飞书机器人, 不传则为数据中心日志记录. Defaults to None.
    """
    body = {
        "msg_type": "post",
        "content": {
            "post": {
                "zh_cn": {
                    "title": title,
                    "content": content
                }
            }
        }
    }

    base_url = f"https://open.feishu.cn/open-apis/bot/v2/hook/{hook.value}"

    r=requests.post(base_url, json=body)
    return r.json()



if __name__ == '__main__':
    import dt
    # content = [
    #     '测试报告地址：http://192.168.31.90\n'
    #     f'测试完成时间：{dt.format()}\n'
    # ]
    content=[
                [
                    {
                        "tag": "text",
                        "text": f'完成时间：{dt.format()}\n'
                    },
                    {
                        "tag": "a",
                        "text": "点击查看报告\n",
                        "href": "http://111.229.11.30:8000/"
                    },
                    {
                        "tag": "at",
                        "user_id": "all"
                    }
                ]
            ]
    r=send_feishu_rich_message('学生端UI自动化测试执行完毕',content)
    print(r)
